package dao;

import domain.Product;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ProductDao {
    //分页查询
    @Select("select * from product order by id desc")
    List<Product> findAll();

    //查询总条数
    @Select("select count(id) from product")
    int findAllCount();

    //根据id查询
    @Select("select * from product where id=#{id}")
    Product findById(int id);

    //新增
    @Insert("insert into product values(null,#{productNum},#{productName},#{goCity},#{goTime},#{price},#{status},#{information},#{img})")
    void add(Product product);

    //修改
    @Update("update product set productNum=#{productNum},productName=#{productName},goCity=#{goCity},goTime=#{goTime},price=#{price},status=#{status},information=#{information},img=#{img} where id= #{id}")
    void update(Product product);

    //删除
    @Delete("delete from product where id=#{id}")
    void del(int id);

    //修改产品状态
    @Update("update product set status=#{status} where id= #{id}")
    void updateStatus(Product product);
}
